// pages/class/class.js
var app = getApp();
Page({


  /**
   * 页面的初始数据
   */
  data: {
    URL: app.globalData.url,
    class_list:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '分类列表'
    })
    var that = this;
    app.getUrl(options);
    wx.request({
      url: app.globalData.url + '/api/shop/goods_category_list',
      success: function (res) {
        // console.log(res.data.inslide);
          console.log(res.data['1'].name);
          
          that.setData({
              class_list: res.data,
              class_item: res.data['1']
          })
      } 
    })
  },
  /**
   * 调用全局返回函数 
   */  
  returnPage:function(e){
      app.returnPage(e);
  },
  /**
   * 选中分类
   */
  toClass:function(e){
      var that = this;
      for (var i in that.data.class_list){
          that.data.class_list[i].select = 0;
      }
      console.log(e.currentTarget.dataset.index);
      that.data.class_list[e.currentTarget.dataset.index].select = 1;
      that.setData({
          class_list:that.data.class_list,
          class_item: that.data.class_list[e.currentTarget.dataset.index]
      })
      console.log(e.currentTarget.dataset);
  },
  /**
   * 
   */
  bindscroll:function(e){
      console.log(e);
  },
  /**
   * 调用全局页面跳转函数
   */
  goToPage: function (e) {
      app.goToPage(e);
  }
})